package com.skhu.as.util;

import java.util.Calendar;

public class DateU {

	private Calendar calendar = null;
	private int year = 9;
	private int month = 99;
	private int dayOfMonth = 99;
	private int hourOfDay = 99;
	private int minute = 99;
	private int second = 99;
	
	public DateU(){
		this.calendar = Calendar.getInstance( );
		this.year = calendar.get(Calendar.YEAR);
		this.month = calendar.get(Calendar.MONTH) + 1;
		this.dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
		this.hourOfDay = calendar.get(Calendar.HOUR_OF_DAY);
		this.minute = calendar.get(Calendar.MINUTE);
		this.second = calendar.get(Calendar.SECOND);
	}
	
	public Calendar getCalendar() {
		return calendar;
	}
	public void setCalendar(Calendar calendar) {
		this.calendar = calendar;
	}
	public int getYear() {
		return year;
	}
	public void setYear(int year) {
		this.year = year;
	}
	public int getMonth() {
		return month;
	}
	public void setMonth(int month) {
		this.month = month;
	}
	public int getDayOfMonth() {
		return dayOfMonth;
	}
	public void setDayOfMonth(int dayOfMonth) {
		this.dayOfMonth = dayOfMonth;
	}
	public int getHourOfDay() {
		return hourOfDay;
	}
	public void setHourOfDay(int hourOfDay) {
		this.hourOfDay = hourOfDay;
	}
	public int getMinute() {
		return minute;
	}
	public void setMinute(int minute) {
		this.minute = minute;
	}
	public int getSecond() {
		return second;
	}
	public void setSecond(int second) {
		this.second = second;
	}

	public String getDate(){
		String monthStr = month < 10 ? "0" + month : "" + month;
		String dayOfMonthStr = dayOfMonth < 10 ? "0" + dayOfMonth : "" + dayOfMonth;
		return year + "" + monthStr + "" + dayOfMonthStr; 
	}
	
	public String getTime(){
		String hourOfDayStr = hourOfDay < 10 ? "0" + hourOfDay : "" + hourOfDay;
		String minuteStr = minute < 10 ? "0" + minute : "" + minute;
		String secondStr = second < 10 ? "0" + second : "" + second;
		return hourOfDayStr + "" + minuteStr + "" + secondStr;
	}
	
	public String getDateTime(){
		return getDate() + "" + getTime();
	}
	
	public static void main(String[] args){
		Calendar oCalendar =  Calendar.getInstance( );
		// 현재 날짜/시간 등의 각종 정보 얻기
	    System.out.println("현재 년: " +  oCalendar.get(Calendar.YEAR));
	    System.out.println("현재 월: " + (oCalendar.get(Calendar.MONTH) + 1));
	    System.out.println("현재 일: " +  oCalendar.get(Calendar.DAY_OF_MONTH));
	    System.out.println(); // 다음줄로 행갈이 하기

	    System.out.println("현재 시: " +  oCalendar.get(Calendar.HOUR_OF_DAY)); // 24시간제
	    System.out.println("현재 분: " +  oCalendar.get(Calendar.MINUTE));
	    System.out.println("현재 초: " +  oCalendar.get(Calendar.SECOND));
	    System.out.println();

	    // 12시간제로 현재 시
	    System.out.print("현재 시: " +  oCalendar.get(Calendar.HOUR));
	    if (oCalendar.get(Calendar.AM_PM) == 0) System.out.println("am");
	    else System.out.println("pm");

	    System.out.println("현재 초의 1000분의1초: " +  oCalendar.get(Calendar.MILLISECOND));

	    System.out.println("현재 요일: " +  oCalendar.get(Calendar.DAY_OF_WEEK)); // 일요일 = 1
	    System.out.println("올해 몇 번째 날: " + oCalendar.get(Calendar.DAY_OF_YEAR)); // 1월 1일 = 1
	    System.out.println("올해 몇 번째 주: " + oCalendar.get(Calendar.WEEK_OF_YEAR)); // 1월 1일은 = 1

	    System.out.println("이번 달의 몇 번째 주: " + oCalendar.get(Calendar.WEEK_OF_MONTH)); // 첫째 주 = 1
	}
	
}
